<?php
$CI = & get_instance();
$CI->load->model('borrower_model');
$overDaysBorrowerList = $CI->borrower_model->get_borrower_notifications_to_send_chitthi();
//echo "<pre>";print_r($overDaysBorrowerList);exit;
?>
<div class="componentheading"><?php echo config_item('project_title');?></div>
<div><?php global_message(); ?></div>
<div class="padding_5topbottom">
    <div class="box-header toggleNext">Mail To: List of people who's borrowed publication are over-dated <?php if(count($overDaysBorrowerList)>0){?><span class="highlight_number" id="over_days_borrower_list"><?php echo count($overDaysBorrowerList);?></span><?php }?></div>
    <div class="toggleBorder pajination">
        <div style="position: absolute;padding: 10px 0px 0px 10px">
            <?php if(count($overDaysBorrowerList)>0){?><a href="<?php echo site_url();?>/cron/email_notification"><strong>Send Email Notification For All At Once</strong></a><?php }?>
        </div>
        <div class="pajination_numbers" style="text-align: right;"></div>
        <div class="box table" style="border:0px;margin: 0px;">
            <table width="100%">
                <thead>
                  <tr>
                        <th width="35%" height="32">Publication Detail</th>
                        <th width="30%">User Detail</th>
                        <th width="15%">Quantity Detail</th>
                        <th width="15%">Date Detail</th>
                        <th width="5%">Action</th>
                  </tr>
               </thead>
           <tbody class="pajination_component">
              <?php if(count($overDaysBorrowerList) > 0):?>
              <?php foreach($overDaysBorrowerList as $overDaysBorrower) : ?>
                    <tr id="tr_send_single_notification_<?php echo ($overDaysBorrower->borrower_qty_id);?>">
                        <td>
                            <div>
                                <div class="left" style="width:70px;margin-top: 5px;"><img src="<?php echo config_item('publication_thumbs_path').$overDaysBorrower->image;?>" /></div>
                                <div class="left" style="width:100px">
                                    <ul class="normalList">
                                        <li><span class="small padding_0left">Name:</span><strong><?php echo $overDaysBorrower->title;?></strong></li>
                                        <li><span class="small padding_0left">Code:</span><strong><?php echo ($overDaysBorrower->coding);?></strong></li>
                                        <li><span class="small padding_0left">Type:</span><strong><?php echo ($overDaysBorrower->type=="np")?"Nepali":"English";?></strong></li>
                                        <li><span class="small padding_0left">Publisher:</span><strong><?php echo $overDaysBorrower->publisher;?></strong></li>
                                    </ul>
                                <?php //echo word_limiter($overDaysBorrower->abstract, 10);?>
                                </div>
                                <div class="clear"></div>
                            </div>
                        </td>
                        <td>
                            <ul class="normalList">
                                 <li><span class="small padding_0left">Name:</span><strong><?php echo $overDaysBorrower->first_name." ".$overDaysBorrower->last_name;?><?php echo ($overDaysBorrower->member_id ==0)?"(Non-member)":"(ID-".$overDaysBorrower->member_id.")";?></strong></li>
                                 <li><span class="small padding_0left">Email:</span><strong><a href="mailto:<?php echo $overDaysBorrower->email;?>"><?php echo $overDaysBorrower->email;?></a></strong></li>
                                 <li><span class="small padding_0left">Address:</span><strong> <?php echo $overDaysBorrower->address1.", ";?><?php echo "".$overDaysBorrower->address2;?></strong></li>
                                 <li><span class="small padding_0left">Phone/Mobile:</span><strong><?php echo $overDaysBorrower->phone1." / ";?><?php echo "".$overDaysBorrower->phone2;?></strong></li>
                            </ul>
                        </td>
                        <td>
                            <ul class="normalList">
                                 <li><span class="small padding_0left">Refundable:</span><strong><?php echo $overDaysBorrower->refundable_qty;?></strong></li>
                                 <li><span class="small padding_0left">Non-refundable:</span><strong><?php echo $overDaysBorrower->non_refundable_qty;?></strong></li>
                                 <li><span class="small padding_0left">Returned:</span><strong> <?php echo $overDaysBorrower->return_qty;?></strong></li>
                                 <li><span class="small padding_0left">Left to return:</span><strong><?php echo (int)($overDaysBorrower->refundable_qty)-(int)($overDaysBorrower->return_qty);?></strong></li>
                            </ul>
                        </td>
                        <td>
                            <ul class="normalList">
                                 <li><span class="small padding_0left">Issue:</span><strong><?php echo $overDaysBorrower->issue_date;?></strong></li>
                                 <li><span class="small padding_0left">Returned:</span><strong><?php echo $overDaysBorrower->return_date;?></strong></li>
                                 <?php echo generate_delay_date($overDaysBorrower->return_date);?>
                            </ul>
                        </td>
                        
                        <td>
                            <form method="post" id="frm_send_single_notification_<?php echo ($overDaysBorrower->borrower_qty_id);?>">
                                <input type="hidden" value="<?php echo $overDaysBorrower->borrower_qty_id;?>" name="borrower_qty_id">
                                <input type="hidden" value="<?php echo $overDaysBorrower->email;?>" name="email">
                                <input type="hidden" value="<?php echo $overDaysBorrower->first_name;?>" name="first_name">
                                <input type="hidden" value="<?php echo $overDaysBorrower->last_name;?>" name="last_name">
                            </form>
                            <div><a onclick="email_single_notification('<?php echo ($overDaysBorrower->borrower_qty_id);?>')" href="javascript:void(0);">Quick Notification</a></div>
                        </td>
                        </tr>
              <?php endforeach; ?>
              <?php else: ?>
                <tr>
                        <td colspan="5">
                        <div class="error_message">
                        No records.
                    </div>
                    </td>
                </tr>
              <?php endif; ?>
            </tbody>
        </table>
      </div>
      <div class="pajination_numbers" style="text-align: right;"></div>
    </div>
</div>
<!--
<div class="padding_5topbottom">
    <div class="box-header toggleNext">Manage To: List of publication which are distributed from store</div>
    <div class="toggleBorder">
        <p>This must contain list of email and sent them individually.</p>
        A very useful aspect of PHP is its ability to manage file uploads to your server. Allowing users to upload a file to your server opens a whole can of worms, so please be careful when enabling file uploads.
        Before you can use PHP to manage your uploads, you must first build an HTML form that lets users select a file to upload. See our HTML Form lesson for a more in-depth look at forms.
        Before you can use PHP to manage your uploads, you must first build an HTML form that lets users select a file to upload. See our HTML Form lesson for a more in-depth look at forms.
        Before you can use PHP to manage your uploads, you must first build an HTML form that lets users select a file to upload. See our HTML Form lesson for a more in-depth look at forms.
        Before you can use PHP to manage your uploads, you must first build an HTML form that lets users select a file to upload. See our HTML Form lesson for a more in-depth look at forms.
        Before you can use PHP to manage your uploads, you must first build an HTML form that lets users select a file to upload. See our HTML Form lesson for a more in-depth look at forms.

    </div>
</div>
-->
<script>
function email_single_notification(borrower_qty_id){
    var form_data = $("#frm_send_single_notification_"+borrower_qty_id).serialize();
    show_loading('tr_send_single_notification_'+borrower_qty_id);
    //$('#tr_send_single_notification_'+borrower_qty_id).html(loading_img);
     $.ajax({
               type: "POST",
               url: "<?php echo site_url('cron/email_single_notification');?>",
               data: form_data,
               success: function(msg){
                   finalMsg = '<td colspan="5" style="vertical-align:middle; text-align:center">'+msg+'</td>';
                   $('#tr_send_single_notification_'+borrower_qty_id).html(finalMsg);
                   $('#tr_send_single_notification_'+borrower_qty_id).remove();
                   var active_page = $(".pajination .pajination_numbers a.active_page").attr('longdesc');
                   //alert(active_page);
                    $('.pajination').pajinate({
                        start_page : active_page,
                        items_per_page : <?php  echo config_item('per_page');?>,
                        num_page_links_to_display: 10,
                        item_container_id : '.pajination_component',
                        nav_panel_id : '.pajination_numbers'
                    });
                    $("#over_days_borrower_list").html(parseInt($("#over_days_borrower_list").html())-1);
               }
             });
}
</script>